<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    em {
      font-style: normal;
    }

    .box {
      padding: 20px 15px;
      box-sizing: border-box;
      margin: 10px auto;
      width: 298px;
      height: 548px;
      border: 1px solid red;
    }

    .box a {
      display: block;
      width: 270px;
      height: 360px;
    }

    .box a img {
      width: 100%;
      height: 100%;
    }

    .box .shop {
      margin: 8px 0 11px 0;
      font-size: 12px;
      line-height: 12px;
      color: #6b6969;
      text-align: center;
    }

    .box .price {
      font-size: 16px;
      line-height: 16px;
      color: #000000;
      text-align: center;
    }

    .box .num {
      margin: 26px 0 24px 50px;
      height: 30px;
    }

    .box .num em {
      margin-right: 10px;
      float: left;
      font-style: normal;
      font-size: 12px;
      line-height: 30px;
      color: #808080;
    }

    .box .num span {
      float: left;
      width: 28px;
      height: 28px;
      line-height: 30px;
      /* background: pink; */
      text-align: center;
      border: 1px solid #e6e6e6;

    }

    .box .num input {
      float: left;
      border: 0;
      width: 58px;
      height: 28px;
      border-top: 1px solid #e6e6e6;
      border-bottom: 1px solid #e6e6e6;
      text-align: center;
    }

    .box .total {
      text-align: center;
      font-size: 16px;
      line-height: 16px;
      color: #000000;
    }
  </style>
</head>

<body>
  <div class="box">
    <a href="###"><img src="./images/2.jpg" alt=""></a>
    <p class="shop">纪梵希 小羊皮口红304</p>
    <p class="price"><em>￥</em><span class="priceV">340</span></p>
    <p class="num">
      <em>数量</em>
      <span class="decrement">-</span>
      <input type="text" class="count" value="0" min="0">
      <span class="increment">+</span>
    </p>
    <p class="total">
      总价￥： <span class="sum">0</span>
    </p>
  </div>



  <script>
    let priceV = document.querySelector(".price .priceV");
    // console.log(priceV.innerHTML); //价格
    let count = document.querySelector(".count")
    // console.log(count.value);//表单的值
    let decrement = document.querySelector(".decrement"); // -
    let increment = document.querySelector(".increment"); // +
    let sum = document.querySelector(".sum"); //sum 总价格

    // -的点击事件
    decrement.addEventListener("click", function () {
      let countValue = count.value; //表单的值
      countValue--;
      count.value = countValue; //把++的值赋值给原先的表单
      let priceValue = priceV.innerHTML; //价格的值

      if (countValue < 0) { //判断表单的数值，假如小于0就赋值为0
        count.value = 0;
      } else {
        sum.innerHTML = countValue * 1 * priceValue * 1;
        // console.log(sum.innerHTML);
      }
    })

    // +的点击事件
    increment.addEventListener("click", function () {
      let countValue = count.value; //表单的值
      countValue++;
      count.value = countValue; //把++的值赋值给原先的表单
      let priceValue = priceV.innerHTML; //价格的值
      // console.log(countValue, priceValue);

      sum.innerHTML = countValue * 1 * priceValue * 1;
      // console.log(sum.innerHTML);
    })
  </script>
</body>

</html>